<!--  -->
<template>
  <div>
    <div class="fixed">
      <div class="serch" :style="{ 'padding-top': barHeight + 'px' }">
        <van-search
          :value="value"
          shape="round"
          placeholder="请输入搜索关键词"
        />
      </div>
    </div>

    <icon imgUrl="/static/icons/home.svg" size="200" color="#02D199"></icon>
    <button @click="subscribe">啊啊啊</button>
    <!-- <tabar></tabar> -->
    <van-icon name="gohome" class-prefix="iconfont" size="66" />
    <van-tabs
      :active="tabactive"
      @change="onChangetag"
      class="aa"
      line-width="30px"
    >
      <van-tab title="标签 1" @click="tab"> </van-tab>
      <van-tab title="标签 2">内容 2</van-tab>
      <van-tab title="标签 3">内容 3</van-tab>
      <van-tab title="标签 4">内容 4</van-tab>
    </van-tabs>
    <vtab :active="0"></vtab>
  </div>
</template>

<script>
import Icon from '../commponents/icon/index'
import Vatabbar from '../commponents/tabbar/vatabbar'
import { getCode } from '../../../src/api/login'
export default {
  name: '',
  components: {
    Icon,
    'vtab': Vatabbar
  },
  onLoad () {
    this.getNavBarHeight()
    this._list()
    this.getSettings()
  },
  data () {
    return {
      active: 0,
      tabactive: 0,
      value: '',
      barHeight: 0
    }
  },

  computed: {
  },
  onPullDownRefresh () {
    console.log('onPullDownRefresh')
  },
  onReachBottom () {
    console.log('onReachBottom')
  },

  mounted () { },

  methods: {
    getSettings () {
      var arr = [
        'J9H_DEvG6dZp29jzqZ3qv6xOAF3rPWhnk5KVCmFXH9Q'
      ]
      wx.getSetting({
        withSubscriptions: true,
        success (res) {
          const app = getApp()
          app.globalDta.subscriptionsSetting = res.subscriptionsSetting
          this.msg = JSON.stringify(res.subscriptionsSetting)
          // 获取用户已订阅的消息
          const keys = res.subscriptionsSetting.itemSettings
          // 2获取服务订阅消息的模板id -> restful -> array

          // 3对比服务已有消息模块 ——》globbalData
          // 3.1用户未开启订阅消息 return
          if (!res.subscriptionsSetting.mainSwitch) {
            return
          }
          // 3.2 用户开启订阅消息 --未设置订阅消息
          if (!keys) {
            app.globalDta.tmplIds = arr
          } else {
            const keysArr = Object.keys(keys)
            app.globalDta.tmplIds = arr.filter((item) => keysArr.indexOf(item) === -1
            )
            // 3.3开启了消息 已经有部分设置 -reject， accept
          }
          // 4等待用户的订阅 
          // console.log(app.globalDta)
          // console.log(res)
          // console.log(res.authSetting)
          // console.log(res.subscriptionsSetting)
        }
      })

    },
    subscribe () {
      wx.requestSubscribeMessage({
        tmplIds: [],
        success (res) {
          console.log(res)
        }
      })
    },
    async _list () {
      getCode(555).then((res) => {
        console.log(res)
        wx.stopPullDownRefresh()
      })
    },
    // tab () {
    //   this.dat()
    // },
    // async dat () {
    //   const result = await axios.post(
    //     'http://localhost:3000/ccc/ss', {
    //       sid: 888
    //     }
    //     // methods: 'GET',
    //     // success: (res) => {
    //     //   console.log('test', res)
    //     // }
    //   )
    //   // .then((res) => {
    //   //   console.log(res)
    //   // }).catch((err) => {
    //   //   console.log('test', err)
    //   // })
    //   console.log('axios result', result)
    // },
    onChangetag (event) {
      console.log(event)
      // this.tabactive = event.mp.detail.index
      wx.showToast({
        title: `切换到标签 ${event.mp.detail.name}`,
        icon: 'none'
      })
    },

    getNavBarHeight () {
      let statusBarHeight = 0
      console.log(statusBarHeight)
      wx.getSystemInfo({
        success: (result) => {
          console.log('res', result)
          statusBarHeight = result.statusBarHeight
          let isiOS = result.system.indexOf('iOS') > -1
          console.log('isIOs', isiOS)
          if (isiOS) {
            this.barHeight = statusBarHeight + 5
          } else {
            this.barHeight = statusBarHeight + 7
          }
        },
        fail: () => { }
      })
    }
  }
}
</script>
<style  >
.aa {
  --tabs-default-color: #02d199;
  --tabs-bottom-bar-color: #02d199;
  --tab-active-text-color: #02d199;
}
.serch {
  width: 70%;
  --search-padding: 0;
  padding-left: 25px;
  padding-bottom: 8px;
  /* @media (max-width: 320px) {
    width: 60%;
  } */
}
.fixed {
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  z-index: 1000;
  background: #ffff;
}
</style>